package com.kgc.warehouse.system.exception;


import com.kgc.warehouse.system.common.CodeMsg;
import com.kgc.warehouse.system.common.ResponseResult;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {


    //用户名错误
    @ExceptionHandler(UnknownAccountException.class)
    public ResponseResult unknownAccountException(UnknownAccountException e)
    {
        e.printStackTrace();
        return new ResponseResult(CodeMsg.USERNAME_NOT_EXIST);
    }

    //密码错误
    @ExceptionHandler(IncorrectCredentialsException.class)
    public ResponseResult incorrectCredentialsException(IncorrectCredentialsException e)
    {
        e.printStackTrace();
        return new ResponseResult(CodeMsg.PASSWORD_ERROR);
    }

    //用户名被禁用
    @ExceptionHandler(LockedAccountException.class)
    public ResponseResult lockedAccountException(LockedAccountException e)
    {
        e.printStackTrace();
        return new ResponseResult(CodeMsg.USER_LOCKED);
    }

    //权限异常
    @ExceptionHandler(AuthorizationException.class)
    public ResponseResult authorizationException(AuthorizationException e)
    {
        e.printStackTrace();
        return new ResponseResult(CodeMsg.USER_NO_AUTHORIZATION);
    }

    // 其它异常
    @ExceptionHandler(Exception.class)
    public ResponseResult  OtherException(Exception e){
        e.printStackTrace();
        return new ResponseResult(CodeMsg.FAIL);
    }
}
